#define _CRT_SECURE_NO_WARNINGS
#include"Heap.h"
void Create(int* a, int n) {
	for (int i = (n - 2) / 2; i >= 0; i--) {
		x(a, n, i);
	}
	int end = n - 1;
	while (end > 0) {
		exchange(&a[0], &a[end]);
		x(a, end, 0);
		end--;
	}
}
void x(int* a, int n,int root) {
	int l = root;
	int child = l * 2 + 1;
	while (child < n) {
		if ((child + 1) < n && a[child + 1] < a[child]) {
			child++;
		}
		if (a[child] < a[l]) {
			exchange(&a[child], &a[l]);
			l = child;
			child = l * 2 + 1;
		}
		else {
			break;
		}
	}
}
void exchange(int* a, int* b) {
	int c = *a;
	*a = *b;
	*b = c;
}
void print(int* a,int n) {
	for (int i = 0; i < n; i++) {
		printf("%d ", a[i]);
	}
	printf("\n");
}
